package com.lwj.designpattern.observer;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wujilee
 * @date 2022/12/29
 * 被观察者
 */
public class ConcreteSubject  implements Subject<Observer>{
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        //主题对象(目标对象)值发生了变化，请通知所有的观察者
        this.notifyAllObservers();
    }

    @Override
    public void registerObserver(Observer obs) {
        // TODO Auto-generated method stub
        list.add(obs);
    }


    @Override
    public void removeObserver(Observer obs) {
        // TODO Auto-generated method stub
        list.remove(obs);
    }

    @Override
    public void notifyAllObservers() {
        for (Observer obs : list) {
            // 更新每一个观察者中的信息
            obs.update(this);
        }
    }
}
